package com.danbay.framework.protocol.mqtt;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @author SJG
 *         2017/11/16.
 */
@ConfigurationProperties(prefix = "mqtt")
@Data
public class MqttProperties {

    /**
     * 服务地址
     */
    private String host = "tcp://localhost";

    /**
     * 服务端口
     */
    private int port = 1883;

    /**
     * 客户端mqtt ID
     */
    private String clientId = "mqtt_client1";

    /**
     * 用户名
     */
    private String userName;

    /**
     * 密码
     */
    private String passWord;

    /**
     * 连接超时时间
     */
    private int connectionTimeout = 10;

    /**
     * 心跳检测间隔
     */
    private int keepAliveInterval = 20;

    /**
     * 默认Qos等级
     */
    private int defaultQos = 1;

    /**
     * 设置是否清空session,这里如果设置为false表示服务器会保留客户端的连接记录，这里设置为true表示每次连接到服务器都以新的身份连接
     */
    private boolean cleanSession = true;

    private Client client;

    public String[] getSubscribes(){
        if(client.getSubscribes() != null) {
            return client.getSubscribes().split(",");
        }
        return new String[]{};
    }

    @Data
    public static class Client{
        /**
         * 订阅主题列表
         */
        private String subscribes;
    }
}
